/*
 * EDAS2 - TetraTech, Inc.
 *
 * Distributable under GPL license.
 * See terms of license at gnu.org.
 */
package com.tetratech.edas2.model;

import java.util.Date;
import javax.persistence.AssociationOverride;
import javax.persistence.AttributeOverride;
import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Embedded;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.OneToOne;
import javax.persistence.PostLoad;
import javax.persistence.PostPersist;
import javax.persistence.PostUpdate;
import javax.persistence.SequenceGenerator;
import javax.persistence.Table;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;
import org.hibernate.annotations.Type;
import org.hibernate.validator.Length;
import org.hibernate.validator.NotNull;

/**
 * Result generated by hbm2java
 */
@Entity
@Table(name = "ED_RESULT")
public class Result extends AttributableUpdateEntity
		implements
			java.io.Serializable {

	private Long uid;
	private SampleFraction sampleFraction;
	private Characteristic characteristic;
	private ResultMeasurementQualifier measurementQualifier;
	private TimeZone timeZoneForLabAnalysisStartTime;
	private ResultValueType valueType;
	private AnalyticalMethod analyticalMethod;
	private BiologicalIntent biologicalIntent;
	private MethodSpecification methodSpecification;
	private CharacteristicPickListValue characteristicPickListValue;
	private ResultStatisticalBase statisticalBase;
	private ResultTemperatureBasis temperatureBasis;
	private ResultType type;
	private Activity activity;
	private ResultStatus status;
	private TimeZone timeZoneOfLabAnalysisEndTime;
	private Organization organization;
	private ResultDetectionCondition detectionCondition;
	private ResultWeightBasis weightBasis;
	private SampleTissueAnatomy sampleTissueAnatomy;
	private Taxon taxon;
	private ResultLabComment labComment;
	private ResultTimeBasis timeBasis;
	private Lifestyle lifestyle;
	private String comments;
	private String dataLoggerLine;
	private String elevationReferenceDatum;
	private Date labAnalysisStartDate;
	private Date labAnalysisStartTime;
	private Date labAnalysisEndDate;
	private Date labAnalysisEndTime;
	private String labName;
	private String measurementBias;
	private String measurementConfidenceInterval;
	private String measurementPrecision;
	private String measurementLowerConfidenceLimit;
	private String measurementUpperConfidenceLimit;
	private String particleSizeBasis;
	private String bioIndividualId;
	private String labAccreditedAuthority;
	private Boolean labAccredited;
	private String samplingPointName;
	private String speciesId;
	private String taxonomistAccreditedAuthority;
	private Boolean taxonomistAccredited;
	private boolean exclude;

	public Result() {
	}

	public Result(Long uid, Activity activity, Organization organization,
			boolean exclude) {
		this.uid = uid;
		this.activity = activity;
		this.organization = organization;
		this.exclude = exclude;
	}

	@Id
	@Column(name = "RES_UID", unique = true, nullable = false, precision = 20, scale = 0)
	@GeneratedValue(generator = "ResultSequence")
	@SequenceGenerator(name = "ResultSequence", sequenceName = "RES_SEQ", allocationSize = 1)
	//@NotNull
	public Long getUid() {
		return this.uid;
	}

	public void setUid(Long uid) {
		this.uid = uid;
	}
	@ManyToOne(fetch = FetchType.LAZY)
	@JoinColumn(name = "SMFRC_UID")
	public SampleFraction getSampleFraction() {
		return this.sampleFraction;
	}

	public void setSampleFraction(SampleFraction sampleFraction) {
		this.sampleFraction = sampleFraction;
	}
	@ManyToOne(fetch = FetchType.LAZY)
	@JoinColumn(name = "CHR_UID")
	public Characteristic getCharacteristic() {
		return this.characteristic;
	}

	public void setCharacteristic(Characteristic characteristic) {
		this.characteristic = characteristic;
	}
	@ManyToOne(fetch = FetchType.LAZY)
	@JoinColumn(name = "RMQLF_UID")
	public ResultMeasurementQualifier getMeasurementQualifier() {
		return this.measurementQualifier;
	}

	public void setMeasurementQualifier(
			ResultMeasurementQualifier measurementQualifier) {
		this.measurementQualifier = measurementQualifier;
	}
	@ManyToOne(fetch = FetchType.LAZY)
	@JoinColumn(name = "TMZONE_UID_LAB_ANALYSIS_START")
	public TimeZone getTimeZoneForLabAnalysisStartTime() {
		return this.timeZoneForLabAnalysisStartTime;
	}

	public void setTimeZoneForLabAnalysisStartTime(
			TimeZone timeZoneForLabAnalysisStartTime) {
		this.timeZoneForLabAnalysisStartTime = timeZoneForLabAnalysisStartTime;
	}
	@ManyToOne(fetch = FetchType.LAZY)
	@JoinColumn(name = "RVTYP_UID")
	public ResultValueType getValueType() {
		return this.valueType;
	}

	public void setValueType(ResultValueType valueType) {
		this.valueType = valueType;
	}
	@ManyToOne(fetch = FetchType.LAZY)
	@JoinColumn(name = "ANLMTH_UID")
	public AnalyticalMethod getAnalyticalMethod() {
		return this.analyticalMethod;
	}

	public void setAnalyticalMethod(AnalyticalMethod analyticalMethod) {
		this.analyticalMethod = analyticalMethod;
	}
	@ManyToOne(fetch = FetchType.LAZY)
	@JoinColumn(name = "BIOINT_UID")
	public BiologicalIntent getBiologicalIntent() {
		return this.biologicalIntent;
	}

	public void setBiologicalIntent(BiologicalIntent biologicalIntent) {
		this.biologicalIntent = biologicalIntent;
	}
	@ManyToOne(fetch = FetchType.LAZY)
	@JoinColumn(name = "MTHSPC_UID")
	public MethodSpecification getMethodSpecification() {
		return this.methodSpecification;
	}

	public void setMethodSpecification(MethodSpecification methodSpecification) {
		this.methodSpecification = methodSpecification;
	}
	@ManyToOne(fetch = FetchType.LAZY)
	@JoinColumn(name = "CPLVAL_UID")
	public CharacteristicPickListValue getCharacteristicPickListValue() {
		return this.characteristicPickListValue;
	}

	public void setCharacteristicPickListValue(
			CharacteristicPickListValue characteristicPickListValue) {
		this.characteristicPickListValue = characteristicPickListValue;
	}
	@ManyToOne(fetch = FetchType.LAZY)
	@JoinColumn(name = "RSBAS_UID")
	public ResultStatisticalBase getStatisticalBase() {
		return this.statisticalBase;
	}

	public void setStatisticalBase(ResultStatisticalBase statisticalBase) {
		this.statisticalBase = statisticalBase;
	}
	@ManyToOne(fetch = FetchType.LAZY)
	@JoinColumn(name = "RTMPB_UID")
	public ResultTemperatureBasis getTemperatureBasis() {
		return this.temperatureBasis;
	}

	public void setTemperatureBasis(ResultTemperatureBasis temperatureBasis) {
		this.temperatureBasis = temperatureBasis;
	}
	@ManyToOne(fetch = FetchType.LAZY)
	@JoinColumn(name = "RES_TYPE_UID")
	public ResultType getType() {
		return this.type;
	}

	public void setType(ResultType type) {
		this.type = type;
	}
	@ManyToOne(fetch = FetchType.LAZY)
	@JoinColumn(name = "ACT_UID", nullable = false)
	@NotNull
	public Activity getActivity() {
		return this.activity;
	}

	public void setActivity(Activity activity) {
		this.activity = activity;
	}
	@ManyToOne(fetch = FetchType.LAZY)
	@JoinColumn(name = "RESSTA_UID")
	public ResultStatus getStatus() {
		return this.status;
	}

	public void setStatus(ResultStatus status) {
		this.status = status;
	}
	@ManyToOne(fetch = FetchType.LAZY)
	@JoinColumn(name = "TMZONE_UID_LAB_ANALYSIS_END")
	public TimeZone getTimeZoneOfLabAnalysisEndTime() {
		return this.timeZoneOfLabAnalysisEndTime;
	}

	public void setTimeZoneOfLabAnalysisEndTime(
			TimeZone timeZoneOfLabAnalysisEndTime) {
		this.timeZoneOfLabAnalysisEndTime = timeZoneOfLabAnalysisEndTime;
	}
	@ManyToOne(fetch = FetchType.LAZY)
	@JoinColumn(name = "ORG_UID", nullable = false)
	@NotNull
	public Organization getOrganization() {
		return this.organization;
	}

	public void setOrganization(Organization organization) {
		this.organization = organization;
	}
	@ManyToOne(fetch = FetchType.LAZY)
	@JoinColumn(name = "RDCND_UID")
	public ResultDetectionCondition getDetectionCondition() {
		return this.detectionCondition;
	}

	public void setDetectionCondition(
			ResultDetectionCondition detectionCondition) {
		this.detectionCondition = detectionCondition;
	}
	@ManyToOne(fetch = FetchType.LAZY)
	@JoinColumn(name = "RWBAS_UID")
	public ResultWeightBasis getWeightBasis() {
		return this.weightBasis;
	}

	public void setWeightBasis(ResultWeightBasis weightBasis) {
		this.weightBasis = weightBasis;
	}
	@ManyToOne(fetch = FetchType.LAZY)
	@JoinColumn(name = "STANT_UID")
	public SampleTissueAnatomy getSampleTissueAnatomy() {
		return this.sampleTissueAnatomy;
	}

	public void setSampleTissueAnatomy(SampleTissueAnatomy sampleTissueAnatomy) {
		this.sampleTissueAnatomy = sampleTissueAnatomy;
	}
	@ManyToOne(fetch = FetchType.LAZY)
	@JoinColumn(name = "TAX_UID")
	public Taxon getTaxon() {
		return this.taxon;
	}

	public void setTaxon(Taxon taxon) {
		this.taxon = taxon;
	}
	@ManyToOne(fetch = FetchType.LAZY)
	@JoinColumn(name = "RLCOM_UID")
	public ResultLabComment getLabComment() {
		return this.labComment;
	}

	public void setLabComment(ResultLabComment labComment) {
		this.labComment = labComment;
	}
	@ManyToOne(fetch = FetchType.LAZY)
	@JoinColumn(name = "RTIMB_UID")
	public ResultTimeBasis getTimeBasis() {
		return this.timeBasis;
	}

	public void setTimeBasis(ResultTimeBasis timeBasis) {
		this.timeBasis = timeBasis;
	}
	@ManyToOne(fetch = FetchType.LAZY)
	@JoinColumn(name = "LIFSTL_UID")
	public Lifestyle getLifestyle() {
		return this.lifestyle;
	}

	public void setLifestyle(Lifestyle lifestyle) {
		this.lifestyle = lifestyle;
	}

	@Column(name = "RES_COMMENTS", length = 4000)
	@Length(max = 4000)
	public String getComments() {
		return this.comments;
	}

	public void setComments(String comments) {
		this.comments = comments;
	}

	@Column(name = "RES_DATA_LOGGER_LINE", length = 15)
	@Length(max = 15)
	public String getDataLoggerLine() {
		return this.dataLoggerLine;
	}

	public void setDataLoggerLine(String dataLoggerLine) {
		this.dataLoggerLine = dataLoggerLine;
	}

	@Column(name = "RES_DEPTH_ALTITUDE_REF_POINT", length = 125)
	@Length(max = 125)
	public String getElevationReferenceDatum() {
		return this.elevationReferenceDatum;
	}

	public void setElevationReferenceDatum(String elevationReferenceDatum) {
		this.elevationReferenceDatum = elevationReferenceDatum;
	}
	@Temporal(TemporalType.DATE)
	@Column(name = "RES_LAB_ANALYSIS_START_DATE", length = 7)
	public Date getLabAnalysisStartDate() {
		return this.labAnalysisStartDate;
	}

	public void setLabAnalysisStartDate(Date labAnalysisStartDate) {
		this.labAnalysisStartDate = labAnalysisStartDate;
	}
	@Temporal(TemporalType.DATE)
	@Column(name = "RES_LAB_ANALYSIS_START_TIME", length = 7)
	public Date getLabAnalysisStartTime() {
		return this.labAnalysisStartTime;
	}

	public void setLabAnalysisStartTime(Date labAnalysisStartTime) {
		this.labAnalysisStartTime = labAnalysisStartTime;
	}
	@Temporal(TemporalType.DATE)
	@Column(name = "RES_LAB_ANALYSIS_END_DATE", length = 7)
	public Date getLabAnalysisEndDate() {
		return this.labAnalysisEndDate;
	}

	public void setLabAnalysisEndDate(Date labAnalysisEndDate) {
		this.labAnalysisEndDate = labAnalysisEndDate;
	}
	@Temporal(TemporalType.DATE)
	@Column(name = "RES_LAB_ANALYSIS_END_TIME", length = 7)
	public Date getLabAnalysisEndTime() {
		return this.labAnalysisEndTime;
	}

	public void setLabAnalysisEndTime(Date labAnalysisEndTime) {
		this.labAnalysisEndTime = labAnalysisEndTime;
	}

	@Column(name = "RES_LAB_NAME", length = 60)
	@Length(max = 60)
	public String getLabName() {
		return this.labName;
	}

	public void setLabName(String labName) {
		this.labName = labName;
	}

	@Column(name = "RES_MEASURE_BIAS", length = 60)
	@Length(max = 60)
	public String getMeasurementBias() {
		return this.measurementBias;
	}

	public void setMeasurementBias(String measurementBias) {
		this.measurementBias = measurementBias;
	}

	@Column(name = "RES_MEASURE_CONF_INTERVAL", length = 15)
	@Length(max = 15)
	public String getMeasurementConfidenceInterval() {
		return this.measurementConfidenceInterval;
	}

	public void setMeasurementConfidenceInterval(
			String measurementConfidenceInterval) {
		this.measurementConfidenceInterval = measurementConfidenceInterval;
	}

	@Column(name = "RES_MEASURE_PRECISION", length = 60)
	@Length(max = 60)
	public String getMeasurementPrecision() {
		return this.measurementPrecision;
	}

	public void setMeasurementPrecision(String measurementPrecision) {
		this.measurementPrecision = measurementPrecision;
	}

	@Column(name = "RES_MEASURE_LOWER_CONF_LIMIT", length = 15)
	@Length(max = 15)
	public String getMeasurementLowerConfidenceLimit() {
		return this.measurementLowerConfidenceLimit;
	}

	public void setMeasurementLowerConfidenceLimit(
			String measurementLowerConfidenceLimit) {
		this.measurementLowerConfidenceLimit = measurementLowerConfidenceLimit;
	}

	@Column(name = "RES_MEASURE_UPPER_CONF_LIMIT", length = 15)
	@Length(max = 15)
	public String getMeasurementUpperConfidenceLimit() {
		return this.measurementUpperConfidenceLimit;
	}

	public void setMeasurementUpperConfidenceLimit(
			String measurementUpperConfidenceLimit) {
		this.measurementUpperConfidenceLimit = measurementUpperConfidenceLimit;
	}

	@Column(name = "RES_PARTICLE_SIZE_BASIS", length = 15)
	@Length(max = 15)
	public String getParticleSizeBasis() {
		return this.particleSizeBasis;
	}

	public void setParticleSizeBasis(String particleSizeBasis) {
		this.particleSizeBasis = particleSizeBasis;
	}

	@Column(name = "RES_BIO_INDIVIDUAL_ID", length = 4)
	@Length(max = 4)
	public String getBioIndividualId() {
		return this.bioIndividualId;
	}

	public void setBioIndividualId(String bioIndividualId) {
		this.bioIndividualId = bioIndividualId;
	}

	@Column(name = "RES_LAB_ACCRED_AUTHORITY", length = 20)
	@Length(max = 20)
	public String getLabAccreditedAuthority() {
		return this.labAccreditedAuthority;
	}

	public void setLabAccreditedAuthority(String labAccreditedAuthority) {
		this.labAccreditedAuthority = labAccreditedAuthority;
	}

	@Column(name = "RES_LAB_ACCRED_YN", length = 1)
	@Type(type = "yes_no")
	public Boolean getLabAccredited() {
		return this.labAccredited;
	}

	public void setLabAccredited(Boolean labAccredited) {
		this.labAccredited = labAccredited;
	}

	@Column(name = "RES_SAMPLING_POINT_NAME", length = 12)
	@Length(max = 12)
	public String getSamplingPointName() {
		return this.samplingPointName;
	}

	public void setSamplingPointName(String samplingPointName) {
		this.samplingPointName = samplingPointName;
	}

	@Column(name = "RES_SPECIES_ID", length = 120)
	@Length(max = 120)
	public String getSpeciesId() {
		return this.speciesId;
	}

	public void setSpeciesId(String speciesId) {
		this.speciesId = speciesId;
	}

	@Column(name = "RES_TAXONOMIST_ACCRED_AUTHORTY", length = 20)
	@Length(max = 20)
	public String getTaxonomistAccreditedAuthority() {
		return this.taxonomistAccreditedAuthority;
	}

	public void setTaxonomistAccreditedAuthority(
			String taxonomistAccreditedAuthority) {
		this.taxonomistAccreditedAuthority = taxonomistAccreditedAuthority;
	}

	@Column(name = "RES_TAXONOMIST_ACCRED_YN", length = 1)
	@Type(type = "yes_no")
	public Boolean getTaxonomistAccredited() {
		return this.taxonomistAccredited;
	}

	public void setTaxonomistAccredited(Boolean taxonomistAccredited) {
		this.taxonomistAccredited = taxonomistAccredited;
	}

	@Column(name = "EXCLUDE_YN", nullable = false, length = 1)
	@Type(type = "yes_no")
	@NotNull
	public boolean isExclude() {
		return this.exclude;
	}

	public void setExclude(boolean exclude) {
		this.exclude = exclude;
	}

	// The following is extra code specified in the hbm.xml files

	private Measurement elevation = new Measurement();
	private Measurement primaryMeasurement = new Measurement();
	private Measurement groupSummaryCountWeight = new Measurement();
	private ResultFrequencyClass resultFrequencyClass;

	@Embedded
	@AttributeOverride(name = "value", column = @Column(name = "RES_DEPTH_HEIGHT"))
	@AssociationOverride(name = "unit", joinColumns = @JoinColumn(name = "MSUNT_UID_DEPTH_HEIGHT"))
	public Measurement getElevation() {
		return this.elevation;
	}

	public void setElevation(Measurement elevation) {
		this.elevation = elevation;
	}

	public void resetElevation() {
		elevation = new Measurement();
	}

	@Embedded
	@AttributeOverride(name = "value", column = @Column(name = "RES_GROUP_SUMMARY_CT_WT"))
	@AssociationOverride(name = "unit", joinColumns = @JoinColumn(name = "MSUNT_UID_GROUP_SUMMARY_CT_WT"))
	public Measurement getGroupSummaryCountWeight() {
		return this.groupSummaryCountWeight;
	}

	public void setGroupSummaryCountWeight(Measurement groupSummaryCountWeight) {
		this.groupSummaryCountWeight = groupSummaryCountWeight;
	}

	@Embedded
	@AttributeOverride(name = "value", column = @Column(name = "RES_MEASURE"))
	@AssociationOverride(name = "unit", joinColumns = @JoinColumn(name = "MSUNT_UID_MEASURE"))
	public Measurement getPrimaryMeasurement() {
		return this.primaryMeasurement;
	}

	public void setPrimaryMeasurement(Measurement primaryMeasurement) {
		this.primaryMeasurement = primaryMeasurement;
	}

	public void resetPrimaryMeasurement() {
		primaryMeasurement = new Measurement();
	}

	@PostLoad
	@PostPersist
	@PostUpdate
	public void afterLoad() {
		if (elevation == null) {
			resetElevation();
		}
		if (primaryMeasurement == null) {
			resetPrimaryMeasurement();
		}
	}

	@OneToOne(cascade = CascadeType.ALL, fetch = FetchType.LAZY, mappedBy = "result")
	public ResultFrequencyClass getResultFrequencyClass() {
		return this.resultFrequencyClass;
	}

	public void setResultFrequencyClass(
			ResultFrequencyClass resultFrequencyClass) {
		this.resultFrequencyClass = resultFrequencyClass;
	}

	// end of extra code specified in the hbm.xml files

}
